package com.maila.xiaoaoschool.image;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.entity.IndexCarouselFigure;
import com.maila.xiaoaoschool.util.Constants;


/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class NetworkImageHolderView implements Holder<IndexCarouselFigure.DataBean> {
    private ImageView imageView;

    BannerCallback callback;

    public NetworkImageHolderView(BannerCallback callback) {
        super();
        this.callback = callback;
    }


    @Override
    public View createView(Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
//        imageView = new ImageView(context);
        imageView=new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        return imageView;
    }

    @Override
    public void UpdateUI(final Context context, final int position, IndexCarouselFigure.DataBean data) {
        imageView.setBackgroundResource(R.drawable.zhanweizhenglunbo);

        Glide.with(context).load(Uri.parse(Constants.URL_ROOT_XIAOAO+data.getImg())).into(imageView);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击事件
                callback.click(position);
//

            }
        });
    }
    public interface BannerCallback{
        void  click(int position);
    }
}
